package com.hunting.company;


import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import org.hibernate.Hibernate;
import util.dao.Pagination;
import com.opensymphony.xwork2.ActionSupport;
public class CompanyAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
   
	private CompanyDao companyDao;
	private Company company;
	private List<Company> list;
	private long id;
	private File upload;
	private UserResume userResume;
	private UserResumeDao userResumeDao;
	private ResumeCompany resumeCompany;
	private ResumeCompanyDao resumeCompanyDaos;
	
	
	
	public UserResume getUserResume() {
		return userResume;
	}
	public void setUserResume(UserResume userResume) {
		this.userResume = userResume;
	}

	public UserResumeDao getUserResumeDao() {
		return userResumeDao;
	}

	public void setUserResumeDao(UserResumeDao userResumeDao) {
		this.userResumeDao = userResumeDao;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	private Pagination <Company> pagination;
	
	public Pagination<Company> getPagination() {
		return pagination;
	}

	public void setPagination(Pagination<Company> pagination) {
		this.pagination = pagination;
	}

	public List<Company> getList() {
		return list;
	}

	public void setList(List<Company> list) {
		this.list = list;
	}

	public CompanyDao getCompanyDao() {
		return companyDao;
	}

	public void setCompanyDao(CompanyDao companyDao) {
		this.companyDao = companyDao;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public String start() throws Exception{
		return SUCCESS;
	}
    
	public String saveCompany() throws Exception{
		this.companyDao.saveOrUpdate(company);
		return SUCCESS;
	}
    
	public String showCompany() throws Exception{
		company = this.companyDao.findById(id);
		return SUCCESS;
	}
	public String deleteCompany()throws Exception{
		System.out.println(id);
		company = this.companyDao.findById(id);
		this.companyDao.delete(company);
		
		return SUCCESS;
	}
	
	public String updateCompany()throws Exception{
		 company = this.companyDao.findById(id);
		 this.companyDao.update(company);
		 
		 return SUCCESS;
	}
	
	private List<ResumeCompany> listResume;
	private Pagination <ResumeCompany> paginations;
	
	public String checkResume()throws Exception{
		//listResume = this.resumeCompanyDaos.findAll();
		if(paginations == null){
			paginations = new Pagination<ResumeCompany>();
		}
		if(paginations.getSize() == 0){
			paginations.setSize(3);
		}
		if(paginations.getNo() == 0){
			paginations.setNo(1);
		}
		this.resumeCompanyDaos.browse(paginations);
		return SUCCESS;
	}
	
	public String browse() throws Exception{
		if(pagination == null){
			 pagination = new Pagination<Company>();
		 }
	     if(pagination.getSize() == 0){
	    pagination.setSize(3);
	     }
	     
		if(pagination.getNo()==0){
   		pagination.setNo(1);
   	}

	    this.companyDao.browse(pagination);
		return SUCCESS;
	}
	
	public String deleteResume() throws Exception{
		resumeCompany = this.resumeCompanyDaos.findById(id);
		this.resumeCompanyDaos.delete(resumeCompany);
		return SUCCESS;
	}
	
	@Override
	public String execute() throws Exception {
		
		return SUCCESS;
	}
	
	public String delete()throws Exception{
		company = this.companyDao.findById(id);
		this.companyDao.delete(company);
		return SUCCESS;
	}
	
	
	public String saveResume() throws Exception{
		System.out.println("-------------->"+upload);
		if(upload!=null){
			userResume = new UserResume();
			userResume.setCompany(company);
			userResume.setData(Hibernate.createBlob(new FileInputStream(this.upload)));
			this.userResumeDao.saveOrUpdate(userResume);
		}
		
		return SUCCESS;
	}
	public ResumeCompany getResumeCompany() {
		return resumeCompany;
	}
	public void setResumeCompany(ResumeCompany resumeCompany) {
		this.resumeCompany = resumeCompany;
	}
	public ResumeCompanyDao getResumeCompanyDaos() {
		return resumeCompanyDaos;
	}
	public void setResumeCompanyDaos(ResumeCompanyDao resumeCompanyDaos) {
		this.resumeCompanyDaos = resumeCompanyDaos;
	}
	public List<ResumeCompany> getListResume() {
		return listResume;
	}
	public void setListResume(List<ResumeCompany> listResume) {
		this.listResume = listResume;
	}
	public Pagination<ResumeCompany> getPaginations() {
		return paginations;
	}
	public void setPaginations(Pagination<ResumeCompany> paginations) {
		this.paginations = paginations;
	}
	

	
}
